﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NENAData.Factory;
using NENAData.LINQ;
using NENAData.NENAProvinces;

namespace NENAData.Transactions.Payments.Cheque
{
    public class ChequeTransactions
    {

        private static MembershipDataContext GetMembershipDB()
        {
            var x = new SQLMembership();
            return x.GetMembershipDB();
        }

        public string NewPayment(int intMemberID, int intPaymentTo, TransactionList.Transactions oTransaction)
        {
            MembershipDataContext db = GetMembershipDB();

            NENAAffiliate oNENAAffiliate = new NENAAffiliate();
            Affiliate oAffiliate = new Affiliate();

            oAffiliate = oNENAAffiliate.GetAffiliate_byAffiliateID(intPaymentTo);

            TransactionPayment NENAtransaction = new TransactionPayment
            {
                Member_ID = intMemberID,
                PaymentTo = intPaymentTo,
                PaymentAmount = Convert.ToDouble(oAffiliate.Membership_Fee),
                TransactionCompleted = true,
                PaymentType = "Cheque",
                PaymentStatus = "Paid by Cheque",
                PaymentDate = DateTime.Now,
                TransactionID_NENA = (Int32)oTransaction
            };

            db.TransactionPayments.InsertOnSubmit(NENAtransaction);
            db.SubmitChanges();
            
            return NENAtransaction.TransactionPaymentID.ToString();
        }

        public void NewPayment(string strAmount, int intMemberID, int intPaymentTo, TransactionList.Transactions  oTransaction)
        {
            MembershipDataContext db = GetMembershipDB();

            TransactionPayment NENAtransaction = new TransactionPayment
                                                     {
                                                         Member_ID = intMemberID,
                                                         PaymentTo = intPaymentTo,
                                                         PaymentAmount = Convert.ToDouble(strAmount),
                                                         TransactionCompleted = true,
                                                         PaymentType = "Cheque",
                                                         PaymentMethod = "Manual",
                                                         PaymentStatus = "Paid by Cheque",
                                                         PaymentReason = "MembershipFees",
                                                         PaymentDate = DateTime.Now,
                                                         TransactionID_NENA = (Int32) oTransaction
                                                     };

            db.TransactionPayments.InsertOnSubmit(NENAtransaction);
            db.SubmitChanges();
        }
    }
}